package com.example.demo.arithmetic.algorithm.queue;

import java.util.Scanner;

/**
 * @Description:
 * @Author: LLL
 * @Date: 2020-03-12 23:22
 **/
public class App {

    public static void main(String[] args) {
        ArrayQueue queue = new ArrayQueue(3);
        char key = ' ';
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;
        while (loop) {
            if (scanner.hasNext()) {
                key = scanner.next().charAt(0);
                switch (key) {
                    case 's':
                        System.out.println(queue.toString());
                        break;
                    case 'a':
                        System.out.println("请输入要添加的元素！");
                        int nextInt = scanner.nextInt();
                        System.out.println(queue.add(nextInt));
                        break;
                    case 'r':
                        try {
                            int remove = queue.remove();
                            System.out.println(remove);
                        } catch (Exception e) {
                            System.out.println(e.getMessage());
                        }
                        break;
                    case 'p':
                        try {
                            int peek = queue.peek();
                            System.out.println(peek);
                        } catch (Exception e) {
                            System.out.println(e.getMessage());
                        }
                    default:
                        break;
                }
            }
        }
    }
}
